package com.servlet;

import com.dao.imp.FindOrder;
import com.entity.Order;
import net.sf.json.JSONArray;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/12/3 13:35
 **/

@WebServlet(name = "GetUserOrderByTimeServlet", value = "/GetUserOrderByTimeServlet")
public class GetUserOrderByTimeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        HttpSession session = request.getSession();
        int user_id = Integer.parseInt(session.getAttribute("userId").toString());
//        int choosePageNum = Integer.parseInt(request.getParameter("pageNum"));
//        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
//        int realStartIndex = (choosePageNum-1)*pageSize;


        String selectSQL = "SELECT * FROM orders WHERE user_id ="+user_id+"   ORDER BY `order_id` desc LIMIT 0,5";

//        System.out.println(selectSQL);

        List<Order> orderList = FindOrder.getOrderList(selectSQL);

//        System.out.println(orderList);
        JSONArray json = JSONArray.fromObject(orderList);
        response.getWriter().print(json);
    }
}
